<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:useBean id="user_login" scope="session" class="software.Use_user"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>软件开发交流平台</title>
	<link href="../css/login.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
		function check_lo(){
			if(form3.name.value==""){
				alert("用户名不能为空");
				form3.name.focus();
				return false;
			}
			else if(form3.pwd.value==""){
				alert("密码不能为空");
				form3.pwd.focus();
				return false;
			}
			else{
				return true;
			}
		}
	</script>
  </head>
  <body>
<%
	// 用户退出登录 行为
	String action =request.getParameter("action");
	if(action !=null){
		if(action.equals("exit")){
			session.removeAttribute("Nickname");
			session.removeAttribute("ID");
			 session.removeAttribute("PhoSrc");
			 session.removeAttribute("Nickname"); 
			 session.removeAttribute("ID"); 
			 session.removeAttribute("PhoSrc"); 
		}
	}
	// 判断用户是否已登录行为
	String Name=(String)session.getAttribute("Nickname");
	String Pwd=null;
	boolean check=false;
	if(Name!=null){
		out.print("<script>alert('您已登录成功...')</script>");
	}
	else{
		Name=request.getParameter("name");
		Pwd=request.getParameter("pwd");
	  	if(Name!=null&&Pwd!=null){
			user_login.setUsername(Name);
			user_login.setPassword(Pwd);
			if(user_login.Che_Login()){
			 	check=true;
			 	String PhoSrc=user_login.getPho();
			 	session.setAttribute("PhoSrc",PhoSrc);
			 	session.setAttribute("Nickname",Name);
			 	session.setAttribute("ID",user_login.getId());
				out.print("<script>alert('恭喜你，登录成功')</script>");
				response.sendRedirect("index.jsp");
			}
			else{
				out.print("<script>alert('登录失败')</script>");
			} 
	  	}
	} 
	%>
 	<jsp:include page="head.jsp" />
    <div id="contianer">
        <div id="login">
		<form method="post" name="form3" action="login.jsp" onsubmit="return check_lo()">
            <input name="name" type="text" class="text1" size="10"/>
            <input name="pwd" type="password" class="text2"/>
            <input name="登陆" type="submit"  value=""class="button1" />
            <input name="取消" type="reset" value="" class="button2" />
 		 </form>
        </div>
    </div>
 	<jsp:include page="footer.jsp" />
  </body>
</html>
